package by.grsu.coctails.model;

import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;
import by.grsu.coctails.R;
import by.grsu.coctails.utils.ContextHolder;
import by.grsu.coctails.utils.StringUtil;

public class Coctail implements Parcelable {

	public static final Parcelable.Creator<Coctail> CREATOR = new Creator<Coctail>() {

		public Coctail[] newArray(int size) {
			return new Coctail[size];
		}

		public Coctail createFromParcel(Parcel in) {
			return new Coctail(in);
		}
	};

	private String name;

	private String image;

	private String history;

	private String instruction;

	private List<Ingredient> listIngredients;

	private String compostionString;

	public Coctail(Parcel in) {
		readFromParcel(in);
	}

	public Coctail(String name, String image, String history, String instruction, List<Ingredient> listIngredients) {
		this.name = name;
		this.image = image;
		this.history = history;
		this.instruction = instruction;
		this.listIngredients = listIngredients;
	}

	public String getName() {
		return name;
	}

	public String getImage() {
		return image;
	}

	public List<Ingredient> getIngredients() {
		return listIngredients;
	}

	public String getHistory() {
		return history;
	}

	public String getInstruction() {
		return instruction;
	}

	public String getCompostionString() {
		return compostionString;
	}

	public void setCompostionString(String compostionString) {
		this.compostionString = compostionString;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(name);
		dest.writeString(image);
		dest.writeString(history);
		dest.writeString(instruction);
		// dest.writeParcelable((Parcelable) listIngredients, flags);

	}

	private void readFromParcel(Parcel in) {
		this.name = in.readString();
		this.image = in.readString();
		this.history = in.readString();
		this.instruction = in.readString();
		// this.listIngredients = in.readParcelable(Ingredient.class
		// .getClassLoader());

	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(name + "\n\n");
		if (!StringUtil.isEmpty(history)) {
			builder.append(ContextHolder.getContext().getString(R.string.history) + "\n" + history + "\n\n");
		}
		if (!StringUtil.isEmpty(instruction)) {
			builder.append(ContextHolder.getContext().getString(R.string.how_create) + ":\n" + instruction + "\n\n");
		}
		builder.append(ContextHolder.getContext().getString(R.string.required_ingredients) + "\n");
		for (Ingredient ingredient : listIngredients) {
			builder.append(ingredient.getName() + " ");
			if (!StringUtil.isEmpty(ingredient.getCount())) {
				builder.append(ingredient.getCount() + " ");
			}

			if (!StringUtil.isEmpty(ingredient.getAmountValue())) {
				builder.append(ingredient.getAmountValue() + " ");
			}

			builder.append("\n");
		}

		return builder.toString();
	}

}
